namespace ASPNETMVC4Tutorial.Migrations
{
    using ASPNETMVC4Tutorial.Models;
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<ASPNETMVC4Tutorial.Models.EFContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true; //false for production.
        }

        protected override void Seed(ASPNETMVC4Tutorial.Models.EFContext context)
        {


            context.Movies.AddOrUpdate(i => i.Title,
            new Movie
            {
                Title = "When Harry Met Sally",
                ReleaseDate = DateTime.Parse("1989-1-11"),
                Genre = "Romantic Comedy",
                Price = 7.99M
            },

             new Movie
             {
                 Title = "Ghostbusters ",
                 ReleaseDate = DateTime.Parse("1984-3-13"),
                 Genre = "Comedy",
                 Price = 8.99M
             },

             new Movie
             {
                 Title = "Ghostbusters 2",
                 ReleaseDate = DateTime.Parse("1986-2-23"),
                 Genre = "Comedy",
                 Price = 9.99M
             },

           new Movie
           {
               Title = "Rio Bravo",
               ReleaseDate = DateTime.Parse("1959-4-15"),
               Genre = "Western",
               Price = 3.99M
           }
   );

           context.Albums.AddOrUpdate(i => i.Title,
             new Album 
             {
                 Title = "The Best Of Men At Work",  
                 Price = 8.99M, 
                 AlbumArtUrl = "/Images/placeholder.gif"
             },
            new Album 
            {
                Title = "A Copland Celebration, Vol. I", 
                Price = 8.99M, 
                AlbumArtUrl = "/Images/placeholder.gif"
            },
            new Album
            { 
                Title = "Worlds", 
                Price = 8.99M,  
                AlbumArtUrl = "/Images/placeholder.gif" 
            },
            
            new Album
            { 
                Title = "For Those About To Rock We Salute You", 
                Price = 8.99M, 
                AlbumArtUrl = "/Images/placeholder.gif"
            }
            );


            context.Products.AddOrUpdate(i=>i.Id,
                new Product
                {
                    Name = "Tomato soup",
                    Category = "Groceries",
                    Price = 1.39M,
                    ActualCost = 5 
                },
                new Product
                {
                    Name = "Yo-yo",
                    Category = "Toys",
                    Price = 3.75M,
                    ActualCost = 10
                },
                new Product
                {
                    Name = "Hammer",
                    Category = "Hardware",
                    Price = 16.99M,
                    ActualCost = 2.05M
                }
                );


            context.Orders.AddOrUpdate(i => i.Id,
                new Order
                {
                    Customer = "Bob"
                },
                new Order
                {
                    Customer = "Toby"
                }
                );



            var products = new List<Product>()            
            {
                new Product() { Name = "Tomato soup", Category = "Groceries", Price = 1.39M, ActualCost=5 } ,
                new Product() { Name = "Yo-yo", Category = "Toys", Price = 3.75M, ActualCost = 10 },
                new Product() { Name = "Hammer", Category = "Hardware", Price = 16.99M, ActualCost = 2.05M }
            };


            var order = new Order() { Customer = "Bob" };
            var od = new List<OrderDetails>()
            {
                new OrderDetails() { Product = products[0], Quantity = 2, Order = order},
                new OrderDetails() { Product = products[1], Quantity = 4, Order = order }
            };
            od.ForEach(o => context.OrderDetails.Add(o));


           

            var student = new Student() { Name = "Toby" };
            var score = new List<Score>()
            {
                new Score() { Course = CourseType.Math, ScoreValue = 99, Student=student },
                new Score() { Course = CourseType.English, ScoreValue = 95, Student=student }
            };

            score.ForEach(s => context.Scores.Add(s));



            context.SaveChanges();
        }
    }
}
